convert MySQL table aggregating multiple rows into JSON object